home *** CD-ROM | disk | FTP | other *** search
/ QRZ! Ham Radio 8 / QRZ Ham Radio Callsign Database - Volume 8.iso / mac / files / t_sys5 / 92052tar.gz / 920528.tar / timer.h < prev    next >
C/C++ Source or Header  |  1991-10-26  |  2KB  |  56 lines

  1. /* @(#) $Header: timer.h,v 1.6 91/10/25 15:01:28 deyke Exp $ */
  2.  
  3. #ifndef _TIMER_H
  4. #define _TIMER_H
  5.  
  6. #ifndef _GLOBAL_H
  7. #include "global.h"
  8. #endif
  9.  
  10. /* Software timers
  11.  * There is one of these structures for each simulated timer.
  12.  * Whenever the timer is running, it is on a linked list
  13.  * pointed to by "Timers". The list is sorted in ascending order of
  14.  * expiration, with the first timer to expire at the head. This
  15.  * allows the timer process to avoid having to scan the entire list
  16.  * on every clock tick; once it finds an unexpired timer, it can
  17.  * stop searching.
  18.  *
  19.  * Stopping a timer or letting it expire causes it to be removed
  20.  * from the list. Starting a timer puts it on the list at the right
  21.  * place.
  22.  */
  23. struct timer {
  24.     struct timer *next;     /* Linked-list pointer */
  25.     struct timer *prev;
  26.     int32 duration;         /* Duration of timer, in ms */
  27.     int32 expiration;       /* Clock time at expiration */
  28.     void (*func) __ARGS((void *));  /* Function to call at expiration */
  29.     void *arg;              /* Arg to pass function */
  30.     char state;             /* Timer state */
  31. #define TIMER_STOP      0
  32. #define TIMER_RUN       1
  33. #define TIMER_EXPIRE    2
  34. };
  35. #define NULLTIMER       (struct timer *)0
  36. /* Useful user macros that hide the timer structure internals */
  37. #define dur_timer(t)    ((t)->duration)
  38. #define run_timer(t)    ((t)->state == TIMER_RUN)
  39.  
  40. /* In timer.c: */
  41. void Xalarm __ARGS((int32 ms));
  42. int Xpause __ARGS((int32 ms));
  43. int32 read_timer __ARGS((struct timer *t));
  44. #define set_timer(t,x)  ((t)->duration = (x))
  45. void start_timer __ARGS((struct timer *t));
  46. void stop_timer __ARGS((struct timer *timer));
  47. int32 next_timer_event __ARGS((void));
  48. char *tformat __ARGS((int32 t));
  49.  
  50. extern int32 Msclock;
  51. extern int32 Secclock;
  52. #define msclock()       (Msclock)
  53. #define secclock()      (Secclock)
  54.  
  55. #endif  /* _TIMER_H */
  56.